<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>添加地址</title>
    <link rel="stylesheet"  href="src/css/base.css?__version=9.4">
    <link rel="stylesheet"  href="src/css/pages.css?__version=9.4">
    <link rel="stylesheet"  href="src/css/LArea.css?__version=9.4">
    <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?8ed2efe5b24e14f351f4d88ba2eb3462";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
    </script>
</head>
<body>
    <div class="init_content" style="display: none;">
    <div class="warp addSite-warp">
        <section class="addrss-box">
            <label class="addrss-item">
                <span>收货人：</span>
                <input type="text" id="name" placeholder="请填写收件人姓名">
            </label>
            <label class="addrss-item">
                <span>联系电话：</span>
                <input type="number" id='phone' placeholder="请填写手机">
            </label>
            <label class="addrss-item"  id="select_contact">
                <span class="inline-block" style="vertical-align: top;">所在地区：</span>
                <div class="inline-block" style="width: 50%">
                    <input type="hidden" name="contact_province_code" data-id="0001" id="contact_province_code" value="" data-province-name="">
                    <input type="hidden" name="contact_city_code" id="contact_city_code" value="" data-city-name="">
                    <input type='text' id="region" placeholder='请选择省市区县' readonly />
                </div>
                <img class="icon-rightrow pull-right" src="src/img/rightrow.png">
            </label>
            <label class="addrss-item">
                <span>详细地址：</span>
                <input type="text" id='address' placeholder="请填写详细地址">
            </label>
        </section>

        <button type="button" class="btn btn-green" onclick='addressSub()'>保存</button>
    </div>
    </div>
    <div class="init_loading">
        <img src="src/img/page_loading.gif?v=1">
    </div>
<script type="text/javascript" src="src/js/jquery-1.10.1.min.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/LAreaData1.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/LArea.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/rem.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/dropload.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/init.js?__version=9.4"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="/src/js/share.js?__version=9.4"></script>
<script>
    addheader("添加地址","javascript:history.back(-1);")
    var area1 = new LArea();
        area1.init({
            'trigger': '#region',
            'valueTo': '#contact_city_code',
            'keys': {
                id: 'id',
                name: 'name'
            },
            'type': 1, 
            'data': LAreaData
        });
</script>
<script>
function addressSub(){
	
	//获取数据
	var name = $('#name').val();
	var phone = $('#phone').val();
	var region = $('#region').val();
	var address = $('#address').val();
	
	//正则
	var phoneVarifi = /^1[34578]\d{9}$/; //手机正则
	
	if(!phoneVarifi.test(phone)){
		alert('手机号码错误，请检查');
		return;
	}
	
	if(region == '地区信息'){
		alert('请选择所在地区');
		return;
	}
	
	$.ajax({
		type:'post',
		url:api_url+'/OpenAPI/v1/address/createUserAddress',
		data:{name:name,phone:phone,region:region,address:address,token:token},
		jsonp: 'callback',//跨域问题
		dataType:'jsonp',//跨域接收数据
		
		success:function (data){
			if(data.code == 0){
				alert('保存成功');
				window.location.href="/siteList.html";
			}else{
				alert('保存失败');
				return;
			}
		},
	
		error:function (){
			alert('网络错误');
			return;
		}
	});
}
</script>
</body>
</html>